import type { IQuery, IResData } from '../indexTypes';
import { exc } from '../apiRoot';
import { defHttp } from '@/utils/http';
import type {
  BannerResult,
  HomeTabResult,
  InformationCategoryItem,
  MiniProgramConfigResult,
  NewsTabResult,
} from './types';

const Api = {
  miniProgramConfig: exc + 'configApp',
  bannerList: exc + 'configBanner/list',
  homeTabList: exc + 'configAppBasisData/list?type=0',
  tabbarList: exc + 'configAppBasisData/list?type=1',
  shareImgList: exc + 'configAppBasisData/list?type=4',
  specialList: exc + 'configAppBasisData/list?type=5',
  newsTabList: exc + 'configAppInformation/list',
  secondLevelCategoryList: exc + 'informationCategory/list',
};

/**
 * @description 小程序全局配置
 * @date 21/07/2022
 * @export
 */
export function miniProgramConfig() {
  return defHttp.get<MiniProgramConfigResult>({
    url: Api.miniProgramConfig,
  });
}

/**
 * @description 轮播图列表
 * @date 21/07/2022
 * @export
 */
export function bannerList() {
  return defHttp.get<IResData<BannerResult>>({
    url: Api.bannerList,
  });
}

/**
 * @description 首页tab菜单
 * @date 21/07/2022
 * @export
 */
export function homeTabList(data: IQuery) {
  return defHttp.get<IResData<HomeTabResult>>({
    url: Api.homeTabList,
    data
  });
}

/**
 * @description 底部tabbar
 * @date 21/07/2022
 * @export
 */
export function tabbarList() {
  return defHttp.get<IResData<HomeTabResult>>({
    url: Api.tabbarList,
  });
}

/**
 * @description 获取分享图配置列表
 * @date 27/09/2022
 * @export
 */
export function shareImgList() {
  return defHttp.get<IResData<HomeTabResult>>({
    url: Api.shareImgList,
  });
}

/**
 * @description 首页新闻tab
 * @date 21/07/2022
 * @export
 */
export function newsTabList() {
  return defHttp.get<IResData<NewsTabResult>>({
    url: Api.newsTabList,
  });
}

/**
 * @description 获取资讯二级分类列表
 * @date 27/07/2022
 * @export
 * @param {number} parentId 父级ID
 */
export function secondLevelCategoryList(parentId: number) {
  return defHttp.get<InformationCategoryItem[]>({
    url: Api.secondLevelCategoryList,
    data: {
      parentId,
    },
  });
}

/**
 * 获取专题列表
 * @export
 * @return {*}
 */
 export function getSpecialList(data: {current: number;size: number;}) {
  return defHttp.get<IResData<HomeTabResult>>({
    url: Api.specialList + `&current=${data.current}&size=${data.size}`,
  });
}
